﻿@model IEnumerable<CmsMediaContent>
@{
    var currentMediaId = ViewBag.CurrentMediaId;
    ResFile = "cms_Media";
}

@helper FileType(CmsMimeType mimeType)
{
    var type = mimeType != null ? mimeType.MimeTypeName : "unknown";
    <b>@_("Type:") </b>@type<br />
}


@functions{
    string AnotherFileType(CmsMimeType mimeType)
    {
        var result = "unknown";
        if (mimeType != null)
        {
            var parts = mimeType.MimeTypeName.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            result = parts.Length > 1 ? parts[1] : "unknown";
        }
        return string.Format("/admin/assets/images/360/icons/{0}.png", result);
    }
    string MediaContentIdentificator(int mediaFileId, string linkedFileName)
    {
        return string.Format(CmsAdminMediaActionModel.MediaContentIdentificatorFormat, mediaFileId, linkedFileName);
    }
}

<div class="b-assets js-pager-container">
    @foreach (var item in Model)
    {<div class="b-assets-item" data-id="@item.Id" data-type="ChangeContentFolder">
        <div class="b-assets-item__head">
            <h2 class="b-assets-item__title">@item.MediaContentName</h2>
            @if (item.MediaId != currentMediaId)
            {
                <span>in @Html.ActionLink(item.Media.FolderName, "Get", "CmsMedia", new { id = @item.MediaId }, new { })</span> <br />
            }
            <input class="b-checkbox b-checkbox-mediacontent" name="MediaContent" type="checkbox" value="@MediaContentIdentificator(item.Id, item.MainFile.LinkedFileName)" />
        </div>
        <div class="b-assets-item__body">
            <span class="b-assets-item__spacer"></span>
            @if (item.MainFile.IsImage)
            {
                <img src="@Url.RouteUrl(CmsAdminRoutes.AdminMediaFilePreviewOriginalRoute, new { fileName = item.MainFile.LinkedFileName })?w=190&h=190" alt="@item.MetaCode" />
            }
            else
            {                
                <img src="@AnotherFileType(item.MainFile.MimeType)" alt="" />	
            }
        </div>
        <div class="b-assets-item__foot">
            @if (item.MainFile.IsImage)
            {
                <a rel="gallery" class="b-icon b-icon_loupe b-fancybox" title="@item.Description" href="@Url.RouteUrl(CmsAdminRoutes.AdminMediaFilePreviewOriginalRoute, new { fileName = item.MainFile.LinkedFileName })">@_("Search")</a>
            }

            <p class="b-assets-item__params">
                <b>@_("Id:") </b>@item.MainFile.Id<br />
                @FileType(item.MainFile.MimeType)
                @if (@item.MainFile.Width.HasValue)
                {
                    <b>@_("W:") </b>@item.MainFile.Width.Value
                }
                @if (@item.MainFile.Height.HasValue)
                {
                    <b>@_("H:") </b>@item.MainFile.Height.Value
                }
                <b>@_("Size:") </b>@item.MainFile.Size

                <br />

                @Html.ActionLink(_("Edit"), "Edit", "CmsMediaContent", new { id = item.Id }, new { @class = "b-icon_edit", title = _("Edit Media") })

                @Html.ActionLink(_("Delete"), "Delete", "CmsMediaContent", new { id = item.Id }, new { @class = "b-icon_delete", title = _("Delete Media") })

                <a href="@Html.RelativePathToAbsolute(item.MainFile.FrontEndUrl)" class="js-copy-media-url">@_("Copy URL")</a>

            </p>
        </div>
    </div>}
</div>
<!--do not reorder HTML tags please-->

<script type="text/javascript">
    $(function () {

        if ($("html").hasClass("ie8") || $("html").hasClass("ie7") || $("html").hasClass("ie6")) {

            $(".js-copy-media-url").bind("click", function () {
                window.clipboardData.setData('Text', $(this).attr("href"));
                $(this).fadeOut('fast').fadeIn('fast');
                return false;
            });

        } else {

            $(".js-copy-media-url").zclip({
                path: "/admin/assets/etc/ZeroClipboard.swf",
                copy: function () {
                    return $(this).attr("href");
                },
                afterCopy: function () {
                    $(this).fadeOut('fast').fadeIn('fast');
                }
            });

        }

        initDraggable(".b-assets-item");
    });
</script>
